#include "GameStateManager.h"
#include <windows.h>
#include "../Common/Common.h"

// ---------------------------------- //

GameStateManager::GameStateManager(void)
	: m_pCurrentState( NULL )
	, m_currentStateType( GameStateType::MAX )
{
}

// ------------------------------------ //

GameStateManager::~GameStateManager(void)
{
	m_pStates.Clear( true );
}

// ------------------------------------ //

IGameState* GameStateManager::GetState( GameStateType::States type )
{
	return m_pStates.GetValue( type );
}

// ------------------------------------ //

void GameStateManager::AddState( GameStateType::States type, IGameState* pState )
{
	pState->SetOwner( this );
	m_pStates.Add( type, pState );
	if ( m_pCurrentState == NULL )
	{
		m_pCurrentState = pState;
		m_currentStateType = type;
		m_pCurrentState->OnEnter( GameStateType::MAX );
	}
}

// ------------------------------------ //

void GameStateManager::ChangeState( GameStateType::States nextType, bool isDeleteOldState )
{
	UNUSED_VARIABLE( isDeleteOldState );

	if ( m_currentStateType != GameStateType::MAX
		&& m_pCurrentState != NULL
		)
	{
		m_pCurrentState->OnExit( nextType );
	}

	m_pCurrentState = m_pStates[ nextType ];
	m_pCurrentState->OnEnter( m_currentStateType );
	m_currentStateType = nextType;
}

// ------------------------------------ //

void GameStateManager::Update( float delta )
{
	if ( m_pCurrentState )
	{
		m_pCurrentState->Update( delta );
	}
}

// ------------------------------------ //

void GameStateManager::Draw( float delta )
{
	if ( m_pCurrentState )
	{
		m_pCurrentState->Draw( delta );
	}
}



